<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>查看菜谱</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <#include "../../include/layui.ftl" />
</head>
<body>

  <div class="layui-fluid" id="content_div">
      <div style="text-align: center;margin: 20px 0px;">
          <h2 id="title_0" style="margin-bottom: 10px;"></h2>
          <span style="float:left;font-size:12px;" id="info_0"></span>
          <table id="table_0" border="1" style="width: 100%;border:1px solid #091119;font-size: 12px;"></table>
      <div>
      <div style="text-align: center;margin: 20px 0px;page-break-before: always;">
          <h2 id="title_1" style="margin-bottom: 10px;"></h2>
          <span style="float:left;font-size:12px;" id="info_1"></span>
          <table id="table_1" border="1" style="width: 100%;border:1px solid #091119;font-size: 12px;"></table>
      <div>
      <div style="text-align: center;margin: 20px 0px;page-break-before: always;">
          <h2 id="title_2" style="margin-bottom: 10px;"></h2>
          <span style="float:left;font-size:12px;" id="info_2"></span>
          <table id="table_2" border="1" style="width: 100%;border:1px solid #091119;font-size: 12px;"></table>
      <div>
      <div style="text-align: center;margin: 20px 0px;page-break-before: always;">
          <h2 id="title_3" style="margin-bottom: 10px;"></h2>
          <span style="float:left;font-size:12px;" id="info_3"></span>
          <table id="table_3" border="1" style="width: 100%;border:1px solid #091119;font-size: 12px;"></table>
      <div>
  </div>
  <script>
      layui.config({
          base: '${path}/plug-in/layuiadmin/' //静态资源所在路径
      }).extend({
          index: 'lib/index' //主入口模块
      }).use(['index','table','jquery'],function () {
          var  $ = layui.$,table = layui.table;
          var fun ={
              opt:{
                  url:"/console/checkNote/rewrite/getRecipes"
              },
              init:function(){
                  var index = layer.load(2, {shade: false}),_this = this;
                  $.getJSON(_this.opt.url,{checkId:parent.checkId},function(rep){
                      try {
                          if (!rep.flag) throw new DOMException("获取数据失败!");
                          _this.parseTableDom(rep.data.recipes,rep.data.checkNote)
                      } catch (e) {
                          layer.msg(e.message);
                      }finally {
                          layer.close(index);
                      }
                  });
              },
              parseTableDom:function(recipes,checkNote){
                  var _this = this;
                  $.each(recipes,function(i,item){
                      var title = "第"+(i+1)+"周菜谱（"+item.startTime+" - "+item.endTime+"）";
                      var html = [];
                      var deliveryType = checkNote.deliveryType == 0? "顺产" : "剖腹产";
                      $('#info_'+i).html("<b>产妇姓名：</b>"+checkNote.maternalName+
                              "<b style='margin-left:10px;'>联系电话：</b>"+checkNote.maternalMobile +
                              "<b style='margin-left:10px;'>分娩方式：</b>"+deliveryType +
                              "<b style='margin-left:10px;'>分娩日期：</b>"+checkNote.deliveryDay.split(" ")[0]+
                              "<b style='margin-left:10px;'>忌口：</b>"+checkNote.avoidFood);
                      html.push('<tr style="height:30px;"><th>时间</th><th>早餐</th><th>中餐</th><th>晚餐</th><th>加餐</th></tr>');
                      html.push(_this.makeTableData(item.recipess));
                      $('#title_'+i).text(title);
                      $('#table_'+i).html(html.join(""));
                  });
              },
              makeTableData:function(recipess){
                  var tableData = [];
                  for (var j = 0;j < recipess.length; j++) {
                      var data = recipess[j];
                      var breakfast =  data.breakfast,lunch = data.lunch,
                              dinner = data.dinner,mealAddition = data.mealAddition;
                      var maxLen = Math.max.apply(null,[breakfast.length,lunch.length,dinner.length,mealAddition.length]);
                      var tr = [];
                      var td1 = [],td2 = [],td3 = [],td4 = [];
                      for (var i = 0;i < maxLen; i++) {
                          if (i < breakfast.length){
                              td1.push(breakfast[i].name);
                          }
                          if (i < lunch.length){
                              td2.push(lunch[i].name);
                          }
                          if (i < dinner.length){
                              td3.push(dinner[i].name);
                          }
                          if (i < mealAddition.length){
                              td4.push(mealAddition[i].name);
                          }
                      }
                      tr.push("<tr>");
                      tr.push("<td style='padding:10px;'>"+data.time+"</td>");
                      tr.push("<td style='padding:10px;'>"+td1.join("<br/>")+"</td>");
                      tr.push("<td style='padding:10px;'>"+td2.join("<br/>")+"</td>");
                      tr.push("<td style='padding:10px;'>"+td3.join("<br/>")+"</td>");
                      tr.push("<td style='padding:10px;'>"+td4.join("<br/>")+"</td>");
                      tr.push("</tr>");
                      tableData.push(tr);
                  }
                  return tableData;
              }
          };
          fun.init();
      });
  </script>

</body>
</html>
